<?php

function insertError($firstName, $surname, $team, $process, $score) {
	$surname = str_replace("'", "''", $surname);
	$sql = "SELECT count(*) as count FROM errortable WHERE firstName = '$firstName' AND surname = '$surname' AND team = '$team' AND process = '$process'";
	$result = mysql_query($sql);
	
	$row = mysql_fetch_array($result);
	$count = $row['count'];
	
	if ($count == 0) {
		if ($score != null) {
			$sql = "INSERT INTO errortable (firstName, surname, team, process, score, dateTime) values ('$firstName', '$surname', '$team', '$process', $score, now());";
		}
		else {
			$sql = "INSERT INTO errortable (firstName, surname, team, process, dateTime) values ('$firstName', '$surname', '$team', '$process', now());";
		}
		mysql_query($sql);
	}
}

function getAllErrorEntries() {
	$sql = "select * from errortable order by id desc";
	$result = mysql_query($sql);
	
	$errorEntries = array();
	while($row = mysql_fetch_array($result)) {
		$errorEntry = new ErrorEntry();
		$errorEntry->firstName = $row['firstName'];
		$errorEntry->surname = $row['surname'];
		$errorEntry->score = $row['score'];
		$errorEntry->process = $row['process'];
		$errorEntry->dateTime = $row['dateTime'];
		
		$errorEntries[] = $errorEntry;
	}
	
	return $errorEntries;
}

function clearErrorTable() {
	$sql = "delete from errortable;";
	mysql_query($sql);
}

?>
